//
//  FootPrintTableViewCell.swift
//  Pods
//
//  Created by eme on 2017/3/31.
//
//

import UIKit
import RickonCore
import UtilCore
import BrandonCore

class FootPrintTableViewCell: UITableViewCell {
    
    @IBOutlet weak var goods_ImageView: UIImageView!        //商品图片
    @IBOutlet weak var goodsName_Label: UILabel!            //商品名称
    @IBOutlet weak var storyName_Label: UILabel!            //店铺名称
    @IBOutlet weak var price_Label: UILabel!                //价格字符
    @IBOutlet weak var addJHD_Button: UIButton!             //加入进货单按钮
    @IBOutlet weak var jinZi_Label: UILabel!                //进字Label
    @IBOutlet weak var clickedImageView: UIImageView!       //是否选中
    @IBOutlet weak var Failure_ImageView: UIImageView!      //是否失效/售罄
    @IBOutlet weak var leftWithimage: NSLayoutConstraint!   //图片(是否选中)距离左边的位置
    @IBOutlet weak var LineView: UIView!
    @IBOutlet weak var IconImageView: UIImageView!
    
    var item:ListModel?{
        didSet{
            if let model = item{
                self.goods_ImageView.setUrlImage(model.img1)
                self.storyName_Label.text = model.brname
                self.IconImageView.image = UIImage(named: AppData.setJINorLinIcon(), in: SansaCore.bundle, compatibleWith: nil)
                self.price_Label.text = AppData.getFinalShowPrice(jinPrice: model.shprice, lingPrice: model.bdprice).getPriceStr()
                if model.istimeby == "1"{
                    self.goodsName_Label.setReplaceText(text: AppConfig.timelimit + model.pdname, replace: AppConfig.timelimit, value: Theme.sansa.collect.xsgtextColor)
                    self.addJHD_Button.isEnabled = false
                }else{
                    self.goodsName_Label.text = model.pdname
                    self.addJHD_Button.isEnabled = true
                }
                if model.pdstate != "3"{
                    
                    self.Failure_ImageView.image = UIImage(named: "failure", in: SansaCore.bundle, compatibleWith: nil)
                    self.addJHD_Button.isEnabled = false
                    
                }else{
                    
                    if model.stock == 0{
                        self.Failure_ImageView.image = UIImage(named: "sellout", in: SansaCore.bundle, compatibleWith: nil)
                        self.addJHD_Button.isEnabled = false
                    }else{
                        self.Failure_ImageView.image = UIImage(named: "")
                        if model.istimeby == "1"{
                            self.addJHD_Button.isEnabled = false
                        }else{
                            self.addJHD_Button.isEnabled = true
                        }
                        
                    }
                }
            }
            
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        LineView.backgroundColor = Theme.v.separate_Line
        goodsName_Label.normal_fontSize(14)
        storyName_Label.normal_fontSize(13)
        price_Label.bold_fontSize(15)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
extension AppData{
   public static func setJINorLinIcon() -> String{
        switch AppData.appState {
        case .audited:
            return "price-jin-bigicon"
        default:
            return "lingImage"
        }
    }
}
